﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICalendar.CalendarProperties;

namespace ICalendar.CalendarProperties
{
    public class RelatedTo : CalendarPropertyBase<string>
    {
        protected override void SetValue(string value)
        {
            this.Value = value;
        }

        protected override string GetValue()
        {
            return this.Value;
        }

        public RelationshipType RelationshipType { get; set; }

        protected override void SetParametersFromXParameters(XParameterCollection xparams)
        {
            if (xparams == null)
                return;

            string relType = xparams.GetValue("RELTYPE");

            if (string.IsNullOrEmpty(relType))
            {
                this.RelationshipType = RelationshipType.Parent;
            }
            else
            {
                this.RelationshipType = (RelationshipType)Enum.Parse(typeof(RelationshipType), relType.Trim(), true);
            }
        }

        protected override XParameterCollection GetXParametersFromParameters()
        {

            return new XParameterCollection
                       {
                           {"RELTYPE", this.RelationshipType.ToString().ToUpperInvariant()},
                       };         
        }        

        protected override string[] GetXReservedParametersNames()
        {
            return new[] {"RELTYPE"};
        }
    }
}